
using System;

using Gtk;
using Gdk;

using stefc.geo.platform;

using MyLocate.cmd;

namespace MyLocate.util
{

	public static class DialogUtil
	{
		/*	
		public static void About(Assembly asm)
		{
			AssemblyTitleAttribute attrTitle = GetAttribute<AssemblyTitleAttribute>(asm);
			AssemblyCopyrightAttribute attrCopyright = GetAttribute<AssemblyCopyrightAttribute>(asm);
			AssemblyTrademarkAttribute attrTrademark = GetAttribute<AssemblyTrademarkAttribute>(asm);
			
			AssemblyName asmName = asm.GetName();
						
			using( AboutDialog dlg = new AboutDialog())
			{
				if(attrTitle!=null) dlg.ProgramName = attrTitle.Title;
				if(attrCopyright!=null) dlg.Copyright = attrCopyright.Copyright;
				if(attrTrademark!=null) dlg.License = attrTrademark.Trademark;
					
				dlg.Logo = new Pixbuf (asm, "icon_app_96");
							
				Version v = asmName.Version;		
				dlg.Version = String.Format("{0}.{1}.{2}", v.Major, v.Minor, v.Build);
				dlg.Run();
				dlg.Destroy();
			}	
		}		
		
		private static T GetAttribute<T>(Assembly asm) where T : Attribute
		{
			return (T)Attribute.GetCustomAttribute(asm, typeof(T));
		}
		*/
		
		public static void Info(string text)
		{
			using(MessageDialog dlg = new MessageDialog(null, 
				DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, text))
			{
				dlg.Title = PlatformManager.GetString("Info.Title");
				dlg.Run();
				dlg.Destroy();
			}
		}
		
		public static void Error(string text)
		{
			using(MessageDialog dlg = new MessageDialog(null, 
				DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, text))
			{
				dlg.Title = PlatformManager.GetString("Error.Title");
				dlg.Run();
				dlg.Destroy();
			}
		}
		
		public static bool Question(string text)
		{
			ResponseType result = ResponseType.No;
			using(MessageDialog dlg = new MessageDialog(null, 
				DialogFlags.Modal, MessageType.Question, ButtonsType.YesNo, text))
			{
				dlg.Title = PlatformManager.GetString("Question.Title");
				result = (ResponseType)dlg.Run();
				dlg.Destroy();
			}
			
			return result == ResponseType.Yes;
		}
		
		public static void BindAction(Gtk.Action action, ICommand command)
		{
			action.Activated += (sender,args) => command.Execute();
		}
		
		public static void BindAction(Gtk.Action action, EventHandler eventHandler)
		{
			action.Activated += eventHandler;
		}
		
		public static void BindButton(Gtk.Button button, ICommand command)
		{
			button.Clicked += (sender,args) => command.Execute();
		}
				
		
	}
}
